home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWSemEvt / FWAplEvt.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.5 KB  |  331 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWAplEvt.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWAPLEVT_H
  11. #include "FWAplEvt.h"
  12. #endif
  13.  
  14. #ifndef FWDSCOPR_H
  15. #include "FWDscOpr.h"
  16. #endif
  17.  
  18. #ifndef FWPART_H
  19. #include "FWPart.h"
  20. #endif
  21.  
  22. #ifndef FWSCPTBL_H
  23. #include "FWScptbl.h"
  24. #endif
  25.  
  26. #ifndef FWSESION_H
  27. #include "FWSesion.h"
  28. #endif
  29.  
  30. // ----- Macintosh Includes -----
  31.  
  32. #ifndef __ASREGISTRY__
  33. #include <ASRegistry.h>
  34. #endif
  35.  
  36. // ----- OpenDoc Includes -----
  37.  
  38. #ifndef SOM_ODAppleEvent_xh
  39. #include <ODAplEvt.xh>
  40. #endif
  41.  
  42. #ifndef SOM_ODMessageInterface_xh
  43. #include <MssgIntf.xh>
  44. #endif
  45.  
  46. //========================================================================================
  47. //    Runtime Information
  48. //========================================================================================
  49.  
  50. #ifdef FW_BUILD_MAC    
  51. #pragma segment fwsemevt1
  52. #endif
  53.  
  54. FW_DEFINE_AUTO(FW_CAppleEvent)
  55.  
  56. //========================================================================================
  57. // CLASS FW_CAppleEvent
  58. //========================================================================================
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    FW_CAppleEvent::FW_CAppleEvent
  62. //----------------------------------------------------------------------------------------
  63.  
  64. FW_CAppleEvent::FW_CAppleEvent(ODAppleEvent* odAppleEvent) :
  65.     FW_CDesc(odAppleEvent)
  66. {
  67.     FW_END_CONSTRUCTOR
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. //    FW_CAppleEvent::FW_CAppleEvent
  72. //----------------------------------------------------------------------------------------
  73.  
  74. FW_CAppleEvent::FW_CAppleEvent(const FW_CPart* fromPart, 
  75.                             ODEventClass eventClass, 
  76.                             ODEventID eventID,
  77.                             const FW_CDesc& addressDesc) :
  78.     FW_CDesc()
  79. {
  80.     FW_UNUSED(fromPart);
  81.     
  82.     FW_SOMEnvironment ev;
  83.     ODMessageInterface* msgInt = FW_CSession::GetMessageInterface(ev);
  84.     fReturnID = msgInt->CreateEvent(ev, eventClass, eventID, addressDesc, 0, *this);
  85. }
  86.  
  87. //----------------------------------------------------------------------------------------
  88. //    FW_CAppleEvent::~FW_CAppleEvent
  89. //----------------------------------------------------------------------------------------
  90.  
  91. FW_CAppleEvent::~FW_CAppleEvent()
  92. {
  93.     FW_START_DESTRUCTOR
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    FW_CAppleEvent::HasAttribute
  98. //----------------------------------------------------------------------------------------
  99.  
  100. FW_Boolean FW_CAppleEvent::HasAttribute(ODDescType key) const
  101. {
  102.     FW_CDesc attribute;
  103.     return (::AEGetAttributeDesc(*this, key, typeWildCard, attribute) == FW_xNoError);
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //    FW_CAppleEvent::GetAttributeByPtr
  108. //----------------------------------------------------------------------------------------
  109.  
  110. void FW_CAppleEvent::GetAttributeByPtr(ODDescType dataType,
  111.                                     void* dataPtr,
  112.                                     Size* dataSize,
  113.                                     Size maxSize,
  114.                                     AEKeyword key) const
  115. {
  116.     Size         actualSize;
  117.     ODDescType     actualType;
  118.     
  119.     FW_FailOnError(::AEGetAttributePtr(*this, key, dataType, &actualType, dataPtr, maxSize, &actualSize));
  120.     
  121.     if (dataType != typeWildCard && actualType != dataType)
  122.         FW_Failure(errAECoercionFail);
  123.         
  124.     if (dataSize)
  125.         *dataSize = actualSize;
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CAppleEvent::PutAttributeByPtr
  130. //----------------------------------------------------------------------------------------
  131.  
  132. void FW_CAppleEvent::PutAttributeByPtr(ODDescType dataType,
  133.                                     const void* dataPtr,
  134.                                     Size dataSize,
  135.                                     AEKeyword key)
  136. {
  137.     FW_ASSERT(!IsNullDescriptor());
  138.     FW_FailOnError(::AEPutAttributePtr(*this, key, dataType, dataPtr, dataSize));
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. //    FW_CAppleEvent::GetAttributeByDesc
  143. //----------------------------------------------------------------------------------------
  144.  
  145. void FW_CAppleEvent::GetAttributeByDesc(AEKeyword key, 
  146.                                         FW_CDesc& desc, 
  147.                                         ODDescType desiredType) const
  148. {
  149.     FW_FailOnError(::AEGetAttributeDesc(*this, key, desiredType, desc));
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CAppleEvent::PutAttributeByDesc
  154. //----------------------------------------------------------------------------------------
  155.  
  156. void FW_CAppleEvent::PutAttributeByDesc(AEKeyword key, const FW_CDesc& desc)
  157. {
  158.     FW_ASSERT(!IsNullDescriptor());
  159.     FW_FailOnError(::AEPutAttributeDesc(*this, key, desc));
  160. }
  161.  
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CAppleEvent::GetSubject
  165. //----------------------------------------------------------------------------------------
  166.  
  167. void FW_CAppleEvent::GetSubject(FW_CDesc& subjectDesc) const
  168. {
  169.     GetAttributeByDesc(keySubjectAttr, subjectDesc);
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    FW_CAppleEvent::SetSubject
  174. //----------------------------------------------------------------------------------------
  175.  
  176. void FW_CAppleEvent::SetSubject(const FW_CDesc& subjectDesc)
  177. {
  178.     FW_ASSERT(!IsNullDescriptor());
  179.     PutAttributeByDesc(keySubjectAttr, subjectDesc);
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    FW_CAppleEvent::GetTarget
  184. //----------------------------------------------------------------------------------------
  185.  
  186. void FW_CAppleEvent::GetTarget(FW_CDesc& targetDesc) const
  187. {
  188.     GetAttributeByDesc(keyAETarget, targetDesc);
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------
  192. //    FW_CAppleEvent::SetTarget
  193. //----------------------------------------------------------------------------------------
  194.  
  195. void FW_CAppleEvent::SetTarget(const FW_CDesc& targetDesc)
  196. {
  197.     PutAttributeByDesc(keyAETarget, targetDesc);
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    FW_CAppleEvent::GetEventClass
  202. //----------------------------------------------------------------------------------------
  203.  
  204. AEKeyword FW_CAppleEvent::GetEventClass() const
  205. {
  206.     AEKeyword     eventClass;
  207.     
  208.     GetAttributeByPtr(typeType, &eventClass, NULL, sizeof(eventClass), keyEventClassAttr);    
  209.     return eventClass;
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    FW_CAppleEvent::SetEventClass
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void FW_CAppleEvent::SetEventClass(AEKeyword eventClass)
  217. {
  218.     FW_ASSERT(!IsNullDescriptor());
  219.     PutAttributeByPtr(typeType, &eventClass, sizeof(eventClass), keyEventClassAttr);
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    FW_CAppleEvent::GetEventID
  224. //----------------------------------------------------------------------------------------
  225.  
  226. AEKeyword FW_CAppleEvent::GetEventID() const
  227. {
  228.     AEKeyword     eventID;
  229.     
  230.     GetAttributeByPtr(typeType, &eventID, NULL, sizeof(eventID), keyEventIDAttr);
  231.     return eventID;
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    FW_CAppleEvent::SetEventID
  236. //----------------------------------------------------------------------------------------
  237.  
  238. void FW_CAppleEvent::SetEventID(AEKeyword eventID)
  239. {
  240.     FW_ASSERT(!IsNullDescriptor());
  241.     PutAttributeByPtr(typeType, &eventID, sizeof(eventID), keyEventIDAttr);
  242. }
  243.  
  244. //----------------------------------------------------------------------------------------
  245. //    FW_CAppleEvent::SendToSelf
  246. //----------------------------------------------------------------------------------------
  247.  
  248. void FW_CAppleEvent::SendToSelf(Environment* ev,
  249.                                 FW_CFrame* toFrame,
  250.                                 FW_CAppleEvent* resultEvent,
  251.                                 ODSendPriority sendPriority,
  252.                                 ODULong timeOutInTicks)
  253. {
  254. FW_UNUSED(ev);
  255. FW_UNUSED(toFrame);
  256. FW_UNUSED(resultEvent);
  257. FW_UNUSED(sendPriority);
  258. FW_UNUSED(timeOutInTicks);
  259.     //msgInt->CreatePartAddrDesc(ev, partAddress, part->GetODPart(ev));
  260.  
  261.  
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. //    FW_CAppleEvent::operator ODAppleEvent*
  266. //----------------------------------------------------------------------------------------
  267.  
  268. FW_CAppleEvent::operator ODAppleEvent*() const
  269. {
  270.     PrivUpdateODDescIfStale();
  271.     PrivODDescChanged();
  272.     return (ODAppleEvent*)PrivGetODDescPtr();
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    FW_CAppleEvent::operator ODAppleEvent**
  277. //----------------------------------------------------------------------------------------
  278.  
  279. FW_CAppleEvent::operator ODAppleEvent**()
  280. {
  281.     PrivDispose();
  282.     PrivODDescChanged();
  283.     return (ODAppleEvent**)PrivGetODDescHandle();
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    FW_CAppleEvent::PrivCreateODDesc
  288. //----------------------------------------------------------------------------------------
  289.  
  290. ODDesc* FW_CAppleEvent::PrivCreateODDesc(Environment* ev) const
  291. {
  292.     ODAppleEvent* appleEvent = new ODAppleEvent;
  293.     appleEvent->InitODAppleEvent(ev);
  294.     
  295.     return appleEvent;
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. //    FW_MakeSetLocalPropertyEvent : Given a local scriptable object, a property type,
  300. //    and a new value for the property, create a recordable apple event that, when execute,
  301. //    sets the specified property to the new value.
  302. //
  303. //    This method is present for illustrative purposes only. ODF 1 does not implement
  304. //    factored event handling or recordability.
  305. //----------------------------------------------------------------------------------------
  306.  
  307. FW_CAppleEvent* FW_MakeSetLocalPropertyEvent(Environment* ev, 
  308.                                 FW_CPart* part, 
  309.                                 FW_MScriptable* theObject,
  310.                                 ODDescType whichProperty,
  311.                                 FW_CDesc& newValue)
  312. {    
  313.     FW_CDesc partAddress;
  314.     ODMessageInterface* msgInt;
  315.     FW_CAppleEvent* setPropertyEvent;
  316.     
  317.     msgInt = FW_CSession::GetMessageInterface(ev);
  318.     
  319.     msgInt->CreatePartAddrDesc(ev, partAddress, part->GetODPart(ev));
  320.     
  321.     setPropertyEvent = FW_NEW(FW_CAppleEvent, (part, kAECoreSuite, kAESetData, partAddress));
  322.     
  323.     FW_CDesc directObject;
  324.     theObject->GetPropertySpecifier(ev, part, whichProperty, directObject);
  325.     
  326.     setPropertyEvent->PutDataByDesc(directObject, keyDirectObject);
  327.     setPropertyEvent->PutDataByDesc(newValue, keyAEData);
  328.     
  329.     return setPropertyEvent;
  330. }
  331.